import {Component, EventEmitter,ViewChild, Input, OnInit, Output} from '@angular/core';
import {Router} from '@angular/router';
import {HttpClient} from '@angular/common/http';
import { InitService } from '../../../public/serve/init/init.service';
import { appTemplateUrl } from '../template.url';
import { template } from '../template.data';
import { RemoveTableService } from '../../../public/serve/remove-table/remove-table.service';
import { Service } from '../../../server/server';
import { HintsService } from '../../../public/serve/hints/hints.service';
import { CudTableService } from '../../../public/serve/cud-table/cud-table.service';
import {MessageService} from 'primeng/api';
declare var $: any;
@Component({
  selector: 'app-template-path-add',
  templateUrl: './template-path-add.component.html',
  styleUrls: ['./template-path-add.component.css']
})
export class TemplatePathAddComponent implements OnInit {

  @Output() onSubmit = new EventEmitter<void>();

  constructor(
    private server: Service,
    public initService: InitService,
    private request: CudTableService,
    private hintsService: HintsService,
    private messageService:MessageService
  ) { }

  ngOnInit() {

  }

  

  public initial:boolean = true;

  /**
   * 新增提交
   * @param info 
   */
  _onSubmit(info: any){
    info.token = template.retrieval.token;
    info.status = Number(info.status);
    info.createBy = this.server.getuserName();
    this.request
    .postRequest(this.server.baseUrl + appTemplateUrl.addExportPath,info)
    .then(res=>{
      
      if(res.result_code === '0000'){
        this.onSubmit.emit();
      }
      this.hintsService.messages(res.message,res.result_code);
      this._init();
      return;
    })
    .catch((err: any) => {
      this.hintsService.messages('error','error');
      this._init();
      return;
    });
  }

  /**
   * 初始化弹窗
   */
  private _init(){
    this.initService._init();
    $("#templatePathAdd").modal('hide');
  }

}
